/*************************************************
filename	: sprite.h
author		: Stefan lulham
desc		: A sprite is a 2D screen element.
*************************************************/
#ifndef D_SPRITE_H
#define D_SPRITE_H

#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <modules\graphics\mesh.h>
#include <modules\graphics\texture.h>
#include <modules\graphics\animatable.h>
#include <helpers\math\delge_math.h>
#include <modules\graphics\graphics_enums.h>

using namespace std;
using namespace DelGE::Helpers::Math;

namespace DelGE
{
	namespace Modules
	{
		namespace Graphics
		{
			class Sprite : public Animatable
			{
			private:
				Mesh* pMesh;
				Texture* pTexture;

				Vector3 oHandlePosition;
				Vector3 oPosition;
				Vector3 oScale;
				float fRotation;
				Color oColor;
				DelGEGraphicsBlendMode eBlendMode;

				int iFrameWidth, iFrameHeight;

				float GetFrameStartU(int iFrame);
				float GetFrameStartV(int iFrame);
				float GetFrameEndU(int iFrame);
				float GetFrameEndV(int iFrame);

				Sprite* pParent;
				vector<Sprite*> vChildVector;

			public:
				Sprite();
				Sprite(Texture* pTexture, int iFrameWidth = -1, int iFrameHeight = -1);
				~Sprite();

				Mesh* GetMesh();
				
				void SetTexture(Texture* pTexture);
				Texture* GetTexture();

				/*void AddAnimation(string sName, int iStartFrame, int iEndFrame, float fFPS = 30.0f);
				void RemoveAnimation(string sName);
				Animation* GetAnimation(string sName);
				Animation* GetCurrentAnimation();
				void PlayAnimation(string sName, DelGEGraphics_Animation_Playstyle ePlaystyle = DelGEGraphics_Animation_Playstyle_Once);
				void StopAnimation();
				void PauseAnimation();
				void ResumeAnimation();
				bool IsAnimationPlaying(string sName = "");*/

				int GetFrameCountX();
				int GetFrameCountY();
				int GetFrameCount();
				int GetFrameWidth();
				int GetFrameHeight();

				void SetHandlePosition(float fX, float fY);
				void SetHandlePosition(const Vector3& rVector);
				void SetHandlePositionX(float fX);
				void SetHandlePositionY(float fY);
				Vector3 GetHandlePosition();
				float GetHandlePositionX();
				float GetHandlePositionY();

				void SetPosition(float fX, float fY);
				void SetPosition(const Vector3& rVector);
				void SetPositionX(float fX);
				void SetPositionY(float fY);
				Vector3 GetPosition(bool bGlobal = true);
				float GetPositionX(bool bGlobal = true);
				float GetPositionY(bool bGlobal = true);

				void SetScale(float fScaleX, float fScaleY);
				void SetScale(const Vector3& rVector);
				void SetScaleX(float fScaleX);
				void SetScaleY(float fScaleY);
				Vector3 GetScale(bool bGlobal = true);
				float GetScaleX(bool bGlobal = true);
				float GetScaleY(bool bGlobal = true);

				void SetRotation(float fRotation);
				float GetRotation(bool bGlobal = true);

				int GetWidth();
				int GetHeight();

				void SetColor(int iRed, int iGreen, int iBlue, int iAlpha = 255);
				void SetColor(const Color& rColor);
				Color GetColor();

				void SetBlendMode(DelGEGraphicsBlendMode eBlendMode);
				DelGEGraphicsBlendMode GetBlendMode();

				void SetParent(Sprite* pSprite);
				void AddChild(Sprite* pSprite);
				void RemoveChild(Sprite* pSprite);

				Sprite *GetParent();
				vector<Sprite*> GetChildren();

				void UpdateAnimation(float fDelta);
				void Update(float fDelta);

				Matrix GetLocalMatrix();
				Matrix GetGlobalMatrix();
			};
		}
	}
}

#endif